package com.jiang.daily.Q1472;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/02/26 14:37
 */
class BrowserHistory {
    private List<String> browser;
    private int cur;

    public BrowserHistory(String homepage) {
        browser = new ArrayList<>();
        browser.add(homepage);
        cur = 0;
    }

    public void visit(String url) {
        while (browser.size() > cur + 1) {
            browser.remove(browser.size() - 1);
        }
        browser.add(url);
        cur++;
    }

    public String back(int steps) {
        cur = Math.max(0, cur - steps);
        return browser.get(cur);
    }

    public String forward(int steps) {
        cur = Math.min(browser.size() - 1, cur + steps);
        return browser.get(cur);
    }
}
